﻿using System;
using System.Runtime.Serialization;

namespace Framework.Core.Dependency.Domain
{
    [DataContract(IsReference = true)]
    public class Module
    {
        public Module(string name, string path)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            Name = name;
            Path = path;
        }

        [DataMember]
        public string Name { get; private set; }

        [DataMember]
        public string Path { get; private set; }

        private bool Equals(Module other)
        {
            return string.Equals(Name, other.Name) && string.Equals(Path, other.Path);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            return Equals((Module)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (Path != null ? Path.GetHashCode() : 0);
            }
        }

        public override string ToString()
        {
            return Name;
        }
    }
}